# defs.bzl
WeatherInfo = provider(fields = ["weather"])
TemperatureInfo = provider(fields = ["temperature"])

def _weather_impl(ctx):
    return WeatherInfo(weather = ctx.build_setting_value)

def _temperature_impl(ctx):
    return TemperatureInfo(temperature = ctx.build_setting_value)

weather_flag = rule(
    implementation = _weather_impl,
    build_setting = config.string(flag = True),
)

temperature_flag = rule(
    implementation = _temperature_impl,
    build_setting = config.int(flag = True),
)

def _impl(ctx):
    forecast_dict = {
        "weather": ctx.attr.weather[WeatherInfo].weather,
        "temperature": ctx.attr.temperature[TemperatureInfo].temperature,
    }
    forecast_tmpl = \
"""
--------------- Weather Forecast ---------------
| Weather: {weather}    Temperature: {temperature} C
------------------------------------------------
"""
    print(forecast_tmpl.format(**forecast_dict))


forecast = rule(
    implementation = _impl,
    attrs = {
        "weather": attr.label(),
        "temperature": attr.label(),
    },
)